__author__ = 'Vincent Liu'

from EmailSender import *
from TradingDates import *
import datetime
import os

content = ""

def CheckExist(fname):
	global content
	if os.path.exists(fname):
		content+= "[INFO] {0} is created\n".format(fname)
		return True
	else:
		content+= "[ERROR] {0} is not existed\n".format(fname)
		return False

def CheckSync():
#	os.system("run_syndataLY")
	cdate = datetime.datetime.now().strftime("%Y%m%d")
	ndate = GetNextDate(cdate)
	fname = "D:\\Log\\sync_z\\" + cdate + ".log.txt"
	'''
	if os.path.exists(fname):
		f = open(fname,'r')
		content = "".join(f.readlines())
		subject = "[Success]"
		f.close()
	else:
		content = fname + " not existed"
		subject = "[Error]"
	'''
	ret = True
	path="P:\\public\\data\\"
	fname = path + "dpx\\" + cdate + ".dpx.csv"
	ret &= CheckExist(fname)
	fname = path + "cacs\\" + ndate + ".cacs.csv"
	ret &= CheckExist(fname)
	fname = path + "index\\000300\\000300_wt\\" + cdate + ".000300_wt.csv"
	ret &= CheckExist(fname)
	fname = path + "index\\000905\\000905_wt\\" + cdate + ".000905_wt.csv"
	ret &= CheckExist(fname)
	fname = path + "dpx_raw\\" + cdate + ".dpx.csv"
	ret &= CheckExist(fname)
	if ret == True:
		subject = "[Success]"
	else:
		subject = "[Error]"
	subject += cdate + " Sync daily data"
	em = EmailController()
	em.mail_user = "pubserver@xtcapital.net"
	em.content = content
	em.mail_pass = "PSxtcapital@123"
	em.to_list.append("yliu@xtcapital.net")
	em.to_list.append("465274312@qq.com")
	em.to_list.append("ncai@xtcapital.net")
	em.subject = subject
	em.SendMail()

if __name__ == "__main__":
	CheckSync()